<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <title>订单宝</title>
    <link rel="stylesheet" href="css/ydui.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="iconfont/iconfont.css">
    <script src="js/ydui.flexible.js"></script>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/ydui.js"></script>
    <script src="js/nuoxia.js"></script>
    <style>
        html,
        body {
            background: #f3f3f3
        }
    </style>
</head>

<body>
    <div class="g-view indexPage" id="indexPage">
        <div class="address">
            <select name="" id="typeId">
                <option value="0">请选择商机类型</option>
                <option v-for="(item, index) in goods_arry" :key="index" :value="item.id">{{item.name}}</option>
            </select>
            <select @change="city" name="" id="provinceId">
                <option value="">请选择省</option>
                <option v-for="(item, index) in province_arry" :key="index" :value="item.id">{{item.name}}</option>
            </select>
            <select name="" id="cityId">
                <option value="">请选择市</option>
                <option v-for="(item, index) in city_arry" :key="index" :value="item.id">{{item.name}}</option>
            </select>
        </div>
        <div class="index-search">
            <input id="searchvalue" type="text" class="search-input" placeholder="按关键词搜索" />
            <a @click="indexView" href="javascript:;" class="btn btn-primary">搜索</a>
        </div>
        <ul class="indexlist">
            <li v-for="(item, index) in product_arry" :key="index">
                <a @click="goinfo(item.id)">
                    <div class="indexlist-fl">
                        <h3>【终端】{{item.title}}</h3>
                        <p v-text="item.description"></p>
                        <div class="index-time-address">
                            <span class="index-address">{{item.province_text}}{{item.city_text}}</span>
                            <span class="index-time">{{item.updatetime_text}}</span>
                        </div>
                    </div>
                    <div class="indexlist-fr">
                        <img :src="item.imgstr" alt="" srcset="">
                        <p>剩余{{item.shengyujihui}}次机会</p>
                    </div>
                </a>
            </li>
        </ul>
    </div>
    <footer class="m-tabbar tabbar-fixed">
        <a href="index.html" class="tabbar-item tabbar-active">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe617;</i>
            </span>
            <span class="tabbar-txt">询盘商机</span>
        </a>
        <a href="setup.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:20px" class="icon iconfont">&#xe698;</i>
            </span>
            <span class="tabbar-txt">设置商机</span>
        </a>
        <a href="release.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:22px" class="icon iconfont">&#xe662;</i>
            </span>
            <span class="tabbar-txt">发布商机</span>
        </a>
        <a href="vip.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe67e;</i>
            </span>
            <span class="tabbar-txt">会员中心</span>
        </a>
    </footer>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/ydui.js"></script>
    <script>
        //var token = "3f4f2f2c-a4ca-4df4-bed3-9e57599298ef";
        //window.localStorage.setItem("token", token);
        var gps = zm.gParaurl();
        var code = gps.code;
        var state = gps.state;
        if (code!=undefined) {
            $.ajax({
                type: "post",
                url: paraurl + "api/index/wechatAuth?tm=" + tm,
                async:false,
                data: {
                    code: code,
                    state:state
                },
                success: function (data) {
                    if (data.code == 1) {
                        $.ajax({
                            type: "post",
                            url: paraurl + "api/user/wxlogin?tm=" + tm,
                            async:false,
                            data: {
                                openid:data.data.openid,
                                nickname:data.data.nickname,
                                headimgurl:data.data.headimgurl,
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    window.localStorage.setItem("token", data.data.token);
                                }
                            }
                        })
                    }
                }
            })
        }
        window.onload = function () {
            var token = window.localStorage.getItem("token")
            var indexPage = new Vue({
                el: "#indexPage",
                data: {
                    province_arry: [],
                    city_arry: [],
                    goods_arry: [],
                    product_arry: [],
                },
                filters: {

                },
                mounted: function () {
                    this.province();
                    this.businessType();
                    this.indexView();
                },
                methods: {
                    province: function () {
                        var _this = this;
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/region/province?tm=" + tm,
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.province_arry = data.data;
                                }
                            }
                        })
                    },
                    city: function () {
                        var _this = this;
                        var id = $("#provinceId option:selected").val()
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/region/index?tm=" + tm,
                            data: {
                                id: id
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.city_arry = data.data
                                }
                            }
                        })
                    },
                    businessType: function () {
                        var _this = this;
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/goods/add?tm=" + tm,
                            data: {
                                token: token
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.goods_arry = data.data;
                                }
                            }
                        })
                    },
                    indexView: function () {
                        YDUI.dialog.loading.open('加载中');
                        var _this = this;
                        var typeId = $("#typeId").val();
                        var provinceId = $("#provinceId").val();
                        var cityId = $("#cityId").val();
                        var searchvalue = $("#searchvalue").val();
                        $.ajax({
                            type: "post",
                            url: paraurl + 'api/goods/index?token=' + token + '&filter={"category_id":' + typeId + ',"title":"' + searchvalue + '","province":"' + provinceId + '","city":"' + cityId + '"}&op={"category_id":"=","title":"like","province":"=","city":"="}' + '&tm=' + tm,
                            success: function (data) {
                                if (data.code == 1) {
                                    var product_arry = data.data.rows;
                                    if (product_arry.length > 0) {
                                        for (var i = 0; i < product_arry.length; i++) {
                                            var imgstr;
                                            var bfb = (1 / product_arry[i].total_num) * product_arry[i].shengyujihui;
                                            if (bfb == 1) {
                                                imgstr = "icon/null.png";
                                            } else if (bfb == 0.75) {
                                                imgstr = "icon/one.png";
                                            } else if (bfb == 0.5) {
                                                imgstr = "icon/three.png";
                                            } else if (bfb == 0.25) {
                                                imgstr = "icon/fore.png";
                                            } else if (bfb == 0) {
                                                imgstr = "icon/five.png";
                                            }
                                            product_arry[i].imgstr = imgstr;
                                        }
                                    }
                                    _this.product_arry = product_arry;
                                    YDUI.dialog.loading.close();
                                } else {
                                    YDUI.dialog.alert(data.msg);
                                }
                            }
                        })
                    },
                    goinfo: function (e) {
                        window.location.href = "html/businessinfo.html?id=" + e
                    }
                }
            })
        }
    </script>
</body>

</html>